// Copyright 2019 The rhyme_lph Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// w [author] rhyme_lph
// S [email]  rhymelph@gmail.com
// B [github] https://github.com/rhymelph

import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/generated/l10n.dart';
import 'package:finance_app/src/provider/setting/gst_provider.dart';
import 'package:finance_app/src/router_gen/router_meta.dart';
import 'package:finance_app/src/utils/date_time_utils.dart';
import 'package:finance_app/src/widgets/button/normal_text_button.dart';
import 'package:finance_app/src/widgets/common_app_bar.dart';
import 'package:finance_app/src/widgets/form/value_select_form.dart';
import 'package:finance_app/src/widgets/input/form_input_field.dart';
import 'package:finance_app/src/widgets/switch/normal_switch.dart';
import 'package:finance_app/src/widgets/wrapper/normal_form_wrapper.dart';
import 'package:flutter/material.dart';

@RouterMeta(paramName: "gstPage")
class GstPage extends StatefulWidget {
  @override
  _GstPageState createState() => _GstPageState();
}

class _GstPageState extends State<GstPage>
    with PagePresenter<GstPage, GstProvider> {
  @override
  PreferredSizeWidget get appBar =>
      getDefaultAppBar(title: S.current.gst, actions: [
        NormalSaveTextButton(
          onTap: provider.onSave,
        )
      ]);

  @override
  Widget get buildWidget => ColoredBox(
        color: Colors.white,
        child: ListView(
          children: [
            listBuilder<bool>(
              selector: (_, __) => __.isSelectGst,
              builder: (BuildContext context, bool value, Widget child) =>
                  PressedOpacityButton(
                onPressed: provider.onChangeGstRegister,
                child: NormalFormWrapper(
                  hasBottomBorder: true,
                  child: NormalSwitch(
                    title: S.current.gstregistered,
                    isSelect: value,
                  ),
                ),
              ),
            ),
            listBuilder<bool>(
              selector: (_, __) => __.isSelectGst,
              builder: (BuildContext context, bool value, Widget child) =>
                  value == true ? _buildGstRegistered() : Container(),
            ),
          ],
        ),
      );

  Widget _buildGstRegistered() => Column(
        children: [
          listBuilder<String>(
            selector: (_, __) => __.reportingAgency,
            builder: (BuildContext context, String value, Widget child) =>
                ValueSelectForm(
              title: S.current.reporting_agency,
              value: value,
              // onTap: provider.onChangeReportingAgency,
              onTap: null,
            ),
          ),
          listBuilder<String>(
            selector: (_, __) => __.filingFrequency,
            builder: (BuildContext context, String value, Widget child) =>
                ValueSelectForm(
              title: S.current.filing_frequency,
              value: value,
              // onTap: provider.onChangeFilingFrequency,
              onTap: null,
            ),
          ),
          listBuilder<String>(
            selector: (_, __) => __.gstRate,
            builder: (BuildContext context, String value, Widget child) =>
                ValueSelectForm(
              title: S.current.gst_rate,
              value: value,
              // onTap: provider.onChangeGstRate,
              onTap: null,
            ),
          ),
          FromInputField(
            controller: provider.gstNumberController,
            focusNode: provider.gstNumberFocusNode,
            tip: S.current.gst_number,
          ),
          listBuilder<String>(
            selector: (_, __) =>
                DateTimeUtils.formatGlobalDateTime(__.gstEffectiveDate),
            builder: (BuildContext context, String value, Widget child) =>
                ValueSelectForm(
              title: S.current.gst_effective_date,
              value: value,
              onTap: provider.onChangeGstEffectiveDate,
            ),
          ),
        ],
      );
}
